import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_function.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/emergency/emergency_res_expert_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/resource/model.dart';

/// 应急专家
class EmergencyResourceExpertController extends GetxController {
  /// 筛选右侧栏控制Key
  final popRightScaffoldKey = GlobalKey<ScaffoldState>();

  /// 搜索使用key
  final GlobalKey<CustomEasyRefreshListState> globalKey = GlobalKey();

  /// 专家名称
  String? expertName;

  /// 职称
  String? professionalTitle;

  /// 专业
  String? major;

  /// 评估状态 1-未评估 2-已评估
  EmergencyAssessStatus? assess;

  Future<List<EmergencyResExpertEntity>> getListData(int pageNum, int pageSize) async {
    final res = await HttpUtil().generateGetRequest<List<EmergencyResExpertEntity>>(
      '${Interface.mainBaseUrl}/emergency//emergencyExperts/getEmergencyExpertsPage',
      queryParameters: {
        'pageNum': pageNum,
        'pageSize': pageSize,
        'expertName': expertName,
        'professionalTitle': professionalTitle,
        'major': major,
        'assess': assess,
      },
    ).execute();
    return res.data ?? [];
  }

  /// 筛选
  void screen() {
    popRightScaffoldKey.currentState?.openEndDrawer();
  }

  /// 搜索
  void refreshPage() {
    globalKey.currentState?.onRefresh();
  }

  /// 选择评估状态
  void showSelect() {
    CustomSelectFunction.selectMultipleBottomSheet<EmergencyAssessStatus>(
      onCallBack: (val) {
        assess = val.first;
        update();
      },
      dataList: EmergencyAssessStatus.assessList,
      checkedList: assess == null ? [] : [assess!],
      isMultiple: false,
    );
  }

  void clearChecked() {
    assess = expertName = professionalTitle = major = null;
    update();
  }

  void confirm() {
    popRightScaffoldKey.currentState?.closeEndDrawer();
    refreshPage();
  }
}
